package pub.wii.cook.thrift.service;

import pub.wii.cook.thrift.Ticket;
import pub.wii.cook.thrift.TicketRequest;
import pub.wii.cook.thrift.TicketResponse;
import pub.wii.cook.thrift.TicketService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

public class TicketServiceImpl implements TicketService.Iface {
    private static final HashMap<Integer, Ticket> DATA = new HashMap<>();
    static {
        Ticket ticket = new Ticket();
        ticket.setId(12);
        ticket.setName("情书");
        ticket.setPrice(59);
        ticket.setPremote(0.6);
        DATA.put(12, ticket);

        ticket = new Ticket();
        ticket.setId(32);
        ticket.setName("龙猫");
        ticket.setPrice(40);
        ticket.setPremote(0.7);
        DATA.put(32, ticket);

        ticket = new Ticket();
        ticket.setId(1);
        ticket.setName("阿凡达");
        ticket.setPrice(50);
        ticket.setPremote(0.9);
        DATA.put(1, ticket);
    }
    @Override
    public TicketResponse getTicket(TicketRequest request) {
        Ticket ticket = DATA.get(request.getId());
        TicketResponse response = new TicketResponse();
        if (ticket != null) {
            response.setCode(0);
            response.setTicket(ticket);
        } else {
            response.setCode(10001);
        }
        return response;
    }

    @Override
    public List<Ticket> listTicket() {
        return new ArrayList<>(DATA.values());
    }
}
